import { http } from "@/utils/http";

export type RechargeOrder = {
  id: number;
  order_no: string;
  user_id: number;
  amount: number;
  status: number;
  payment_type?: string;
  transaction_no?: string;
  paid_at?: string;
  created_at: string;
  updated_at: string;
};

export type RechargeOrderResponse = {
  success: boolean;
  code: number;
  message: string;
  data: RechargeOrder;
};

export type RechargeOrderListResponse = {
  success: boolean;
  code: number;
  message: string;
  data: RechargeOrder[];
  pagination: {
    page: number;
    page_size: number;
    total: number;
    total_page: number;
  };
};

export type PaginationParams = {
  page?: number;
  page_size?: number;
};

/** 创建储值订单 */
export const createRechargeOrder = (data: Partial<RechargeOrder>) => {
  return http.request<RechargeOrderResponse>("post", "/recharge/order", { data });
};

/** 获取储值订单列表 */
export const getRechargeOrders = (params?: PaginationParams) => {
  return http.request<RechargeOrderListResponse>("get", "/recharge/order", { params });
};

/** 获取储值订单详情 */
export const getRechargeOrderById = (id: number) => {
  return http.request<RechargeOrderResponse>("get", `/recharge/order/${id}`);
};

/** 更新储值订单 */
export const updateRechargeOrder = (id: number, data: Partial<RechargeOrder>) => {
  return http.request<RechargeOrderResponse>("put", `/recharge/order/${id}`, { data });
};

/** 删除储值订单 */
export const deleteRechargeOrder = (id: number) => {
  return http.request("delete", `/recharge/order/${id}`);
};